package oop;

/**
 * @ClassName : oop.Demo07
 * @Author : LV88VL
 * @Date: 2021/2/3 11:38
 * @Description : 数组
 */
public class Demo07 {
    public static void main(String[] args) {
        /**
        数组的声明以及创建
        int[] a=new int[10];*/
        /**增强for循环
        int [] b={1,2,3,4,5};
        for (int array :b){
            System.out.println(array);
        }*/
        int [] a={5,4,2,3,8};
        int[] b = maopao(a);
        printArray(b);
       /* //多维数组的打印
        int [] [] c={{1,2},{3,4},{5,6},{7,8}};
        for (int i = 0; i < c.length; i++) {
            for (int j = 0; j < c[i].length; j++) {
                System.out.println(c[i][j]);
            }
        }*/
    }
    //数组反转使用
    public static int [] reverse(int[] a){
        int [] result=new int[a.length];
        for (int i=0, j= a.length-1;i<a.length;i++,j--){
            result[j]=a[i];
        }
        return result;
    }
    //打印数组元素
    public static void printArray(int[] a){
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i]+"\t");
        }
    }
    //冒泡排序(优化)
    public static int [] maopao(int[] a) {
        int temp=0;

        for (int i = 0; i < a.length-1; i++) {
            boolean flag=false;
            for (int j = 0; j <a.length-1-i ; j++) {
                if (a[j]>a[j+1]){
                    temp=a[j];
                    a[j]=a[j+1];
                    a[j+1]=temp;
                    flag=true;
                }
            }
            if (flag==false){
                break;
            }
        }
        return a;
    }

}
